define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'withdraw/index' + location.search,
                    add_url: 'withdraw/add',
                    multi_url: 'withdraw/multi',
                    import_url: 'withdraw/import',
                    table: 'withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'createtime',
                columns: [
                    [
                        {field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
                        {field: 'admin.nickname', title:'昵称', searchable:false},
                        {field: 'type', title: "类型", operate: '=', searchList:{"1":"收入","2":"支出"},visible:false},
                        {field: 'money', title: "提现金额(分)",searchable:false},
                        {field: 'before', title: "变动前(分)",searchable:false},
                        {field: 'after', title: "变动后(分)",searchable:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                            {
                                name: 'check',
                                text: '审核',
                                title: '审核',
                                classname: 'btn btn-info btn-xs btn-ajax', 
                                icon: 'fa fa-check',
                                url: 'withdraw/check/id/{ids}',
                                confirm: '是否同意该请求？',
                                refresh: true,
                                disable: function(row){
                                    return table.attr('data-operate-check') != 1 || row.type != 2 || row.status != 0;
                                },
                                visible: function(row){
                                    return table.attr('data-operate-check') == 1 && row.type == 2 && row.status == 0;
                                },
                                extend: '', //扩展的扩展属性，FastAdmin1.4.0+支持function
                            },
                        ],formatter: Table.api.formatter.operate, visible: table.attr('data-operate-check') == 1}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $('#c-money').on('input', function(){
                var money = parseFloat($(this).val());
                if(money > 0){
                    var fee = money * scale / 100;
                    fee = fee.toFixed(2);
                    console.log(fee);
                    $('#c-fee').html(fee);
                    $('#c-fee').parent().removeClass('hide');
                }else{
                    console.log(0);
                    $('#c-fee').empty();
                    $('#c-fee').parent().hide();
                }
                
            });
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});